package cn.kgc.shiroday03.controller;

import cn.kgc.shiroday03.commons.CodeMsg;
import cn.kgc.shiroday03.commons.ResponseResult;
import cn.kgc.shiroday03.entity.Permission;
import cn.kgc.shiroday03.service.PermissionService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/6/7
 * @Description:
 */
@RestController
@RequestMapping("permission")
@Api(tags = "权限模块")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @GetMapping("list")
    public ResponseResult permissionList() {
        List<Permission> list = permissionService.list();
        return new ResponseResult(CodeMsg.SUCCESS, null, list);
    }

    @GetMapping("treeSelect")
    public ResponseResult  treeSelect(){
        return permissionService.treeSelect();
    }


    @PostMapping("add")
    public ResponseResult  addPermission(Permission permission){

        permissionService.save(permission);
        return  new ResponseResult(CodeMsg.SUCCESS);

    }

    @GetMapping("selectById")
    public ResponseResult  selectById(Integer id){

        Permission permission = permissionService.getById(id);

        return  new ResponseResult(CodeMsg.SUCCESS,null,permission);

    }


    @PostMapping("update")
    public ResponseResult  update(Permission permission){

        permissionService.updateById(permission);
        return new ResponseResult(CodeMsg.SUCCESS);
    }



    @GetMapping("delete")

    public ResponseResult  deleteById(Integer id){
       return permissionService.deleteById(id);
    }

}
